package pwd.allen;

import com.alibaba.druid.stat.DruidStatManagerFacade;
import com.alibaba.druid.support.json.JSONUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.util.FileCopyUtils;
import pwd.allen.config.DBConfig;
import pwd.allen.dao.PersonDao;
import pwd.allen.entity.Person;

import java.io.FileWriter;
import java.io.IOException;

/**
 * 加上以下参数，能通过statViewServlet的jmxUrl远程监控druid的信息
 * -Dcom.sun.management.jmxremote.port=4090 -Dcom.sun.management.jmxremote.rmi.port=4090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.9.135
 *
 * 拓展：DruidStatManagerFacade.getInstance()提供了监控信息，可以基于它展示信息
 *
 * @author 门那粒沙
 * @create 2021-12-05 9:09
 **/
public class SpringDaoMain {

    public static void main(String[] args) throws InterruptedException, IOException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DBConfig.class);

        while (Thread.activeCount() > 1) {
            Thread.sleep(1000);
//            String jsonString = JSONUtils.toJSONString(DruidStatManagerFacade.getInstance().getDataSourceStatDataList());
//            FileCopyUtils.copy(jsonString, new FileWriter(System.getProperty("user.home") + "\\Desktop\\test.json"));
        }
    }
}
